<?php if (!defined("BASEPATH")) exit("No direct script access allowed"); ?>

<script type="text/javascript">
	Ext.onReady(function() {

		var winContinent; // edit ablak
		var continentForm; // form panel

		var store = new Ext.data.JsonStore({
			totalProperty: 'total', 
			root: 'results', 
			sortInfo: {field: 'conName', direction: 'ASC'},
			remoteSort: true,
			proxy : new Ext.data.HttpProxy({
				url: '<?=site_url()?>admin/get_continent',
				method: 'GET'
			}),
			fields: [
				{name: 'conId'},
				{name: 'conName'},
				{name: 'conUrlName'},
				{name: 'conLatitude'},
				{name: 'conLongitude'},
				{name: 'e2cTempFlag'}
			]
		});

		var conContextMenuCon = new Ext.menu.Menu({
			items: [{
				id: 'majFilterCon',
				iconCls: 'icon-zoom',
				text: ''
			}],
			listeners: {
				itemclick: function(item) {
					switch (item.id) {
						case 'majFilterCon': {
							Ext.getCmp('pagePanel').findById('majGrid').expand();
							Ext.getCmp('majGrid').getStore().load({params: {fields:'["conName"]', query: Ext.getCmp('conGrid').getSelectionModel().getSelections()[0].data.conName}});
						} break;
					}
				}
			}
		});

		var conGrid = new Ext.grid.GridPanel({
			store: store,
			id: 'conGrid',
			viewConfig:{
				emptyText: '<?=$this->db->escape_str($this->lang->line("THERE_IS_CURRENTLY_NO_DATA_TO_DISPLAY"))?>',
				getRowClass: function(record, index) {
					if(record.data.e2cTempFlag == 'I') return 'temp_data_exists';
					else return '';
				}
			},
			columns: [
				{id: 'conName', header: '<?=$this->db->escape_str($this->lang->line("CONTINENT"))?>', width: 200, sortable: true, dataIndex: 'conName'}
			],
			stripeRows: true,
			autoExpandColumn: 'conName',
			autoHeight: true,
			autoWidth: true,
			sm: new Ext.grid.RowSelectionModel({singleSelect:true}),

			listeners: {

				rowdblclick: function(grid, rowIndex, event) {
					if(rowIndex != 'new') {
						var record = grid.getStore().getAt(rowIndex);
					} else {
						var record = new Object();
						record.data = new Object();
					}
					DataEdit.showWindow('CON', ((rowIndex != 'new')?(''):('-')) + record.data.conId)
				}

				,rowcontextmenu: function(grid, index, event) {
					event.stopEvent();
					if(Ext.getCmp('conGrid').getSelectionModel().getSelections().length > 0) {
						Ext.getCmp('majFilterCon').setText('<?=$this->db->escape_str($this->lang->line("REFINE_THE_COURSES_WITH_THE_SELECTED_ITEM"))?> - ' + Ext.getCmp('conGrid').getSelectionModel().getSelections()[0].data.conName);
						conContextMenuCon.showAt(event.xy);
					}
				}

			},
			border: false,
			frame: false,

			tbar: {
				items: [
					{
						icon: '<?=MEDIA?>icon/application_form_edit.png',
						text: '<?=$this->db->escape_str($this->lang->line("EDIT"))?>',
						ref: '../editBtn',
						disabled: true,
						handler: function() {
							Ext.getCmp('conGrid').fireEvent('rowdblclick', Ext.getCmp('conGrid'), Ext.getCmp('conGrid').store.indexOf(Ext.getCmp('conGrid').getSelectionModel().getSelected()), new Object());
						}
					}, {
							xtype: 'tbseparator'
					},
					{
						icon: '<?=MEDIA?>icon/application_form_preview.png',
						text: '<?=$this->db->escape_str($this->lang->line("PREVIEW"))?>',
						ref: '../previewBtn',
						disabled: true,
						handler: function(){
							window.open('<?=site_url()?>preview/' + conGrid.getSelectionModel().getSelections()[0].data.conUrlName);
						}
					}, {
						xtype: 'tbseparator'
					}, {
						icon: '<?=MEDIA?>icon/application_form_publish.png',
						text: '<?=$this->db->escape_str($this->lang->line("PUBLICATION"))?>',
						ref: '../publishBtn',
						disabled: true,
						handler: function(){
							DataEdit.publish('CON', conGrid.getSelectionModel().getSelections()[0].data.conId, conGrid.getSelectionModel().getSelections()[0].data.conName, 1);
						}
					}, {
						xtype: 'tbseparator'
					}, {
						icon: '<?=MEDIA?>icon/application_form_publish_delete.png',
						text: '<?=$this->db->escape_str($this->lang->line("CANCELLING_OF_UNPUBLISHED_DATA"))?>',
						ref: '../publishBtnDelete',
						disabled: true,
						handler: function(){
							DataEdit.publish('CON', conGrid.getSelectionModel().getSelections()[0].data.conId, conGrid.getSelectionModel().getSelections()[0].data.conName, 0);
						}
					}
				]
				/*
				items: [{
						icon: '<?=MEDIA?>icon/application_form_add.png',
						text: '<?=$this->db->escape_str($this->lang->line("ADD_NEW_CONTINENT"))?>',
						handler: function(){
							DataEdit.showWindow('CON', -1)
						}
					}, {
							xtype: 'tbseparator'
					}, {
						icon: '<?=MEDIA?>icon/application_form_delete.png',
						text: '<?=$this->db->escape_str($this->lang->line("DELETE"))?>',
						ref: '../removeBtn',
						disabled: true,
						handler: function() {
							DataEdit.delete('CON', conGrid.getSelectionModel().getSelections()[0].data.conId, conGrid.getSelectionModel().getSelections()[0].data.conName);
						}
					}
				] */
			},

			plugins:[
				new Ext.ux.grid.Search({
					minChars:2,
					iconCls: 'icon-zoom',
					searchText:'<?=$this->db->escape_str($this->lang->line("SEARCH"))?>',
					position:'top',
					minCharsTipText:'<?=$this->db->escape_str($this->lang->line("MINIMUM_TWO_CHARACTERS_IS_REQUIRED"))?>',
					selectAllText: '<?=$this->db->escape_str($this->lang->line("SELECT_ALL"))?>',
					width:200,
					disableIndexes:[],
					autoFocus:true
				})]

		});

		conGrid.render('grid-table-continent');

		conGrid.getSelectionModel().on('selectionchange', function(sm){
			Ext.getCmp('conGrid').editBtn.setDisabled(sm.getCount() < 1);
			Ext.getCmp('conGrid').publishBtn.setDisabled(!(sm.getCount() && sm.getSelected().data.e2cTempFlag == 'I'));
			Ext.getCmp('conGrid').publishBtnDelete.setDisabled(!(sm.getCount() && sm.getSelected().data.e2cTempFlag == 'I'));
			Ext.getCmp('conGrid').previewBtn.setDisabled(sm.getCount() < 1);
		});

		store.load();


	})
</script>


<div id="grid-table-continent"></div>